#pragma once

#include"RBTree.h"
#include<iostream>
using namespace std;

namespace Map
{
	template<class K, class V>
	class map
	{
		struct mapofT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:


		typedef typename RBTree<K, pair<const K, V>, mapofT>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, mapofT>::const_iterator const_iterator;

		V& operator[] (const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key,V()));
													
			return ret.first->second;
		}

		pair<iterator,bool> insert(const pair<K,V>& kv)
		{
			return _t.insert(kv);
		}
		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator begin()const
		{
			return _t.begin();
		}

		const_iterator end()const
		{
			return _t.end();
		}
	private:
		RBTree<K, pair<const K, V>, mapofT> _t;
	};
}